<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="rs1" class="weaver.conn.RecordSet" scope="page"/>
<jsp:useBean id="bb" class="weaver.general.BaseBean"/>
<jsp:useBean id="resourceInfo" class="weaver.hrm.resource.ResourceComInfo"/>
<%
    String xmmc = Util.null2String( request.getParameter( "xmmc" ) );
    int lc = Util.getIntValue( request.getParameter( "lc" ) );
    List<Map<String, String>> mapList = new ArrayList<>();
    JSONObject jsonData = new JSONObject();
    String sql = "select id from formtable_main_683 where zblx = ? and lc=? ";
    rs.executeQuery( sql, xmmc,lc);
    rs.next();
    String mainid = Util.null2String(rs.getString( "id" ));
    //明细表1
    rs1.executeQuery("select tbr from formtable_main_683_dt2 where mainid='"+mainid+"' and sftt='0'");
    while (rs1.next()){
        Map<String, String> dataMap = new HashMap<>();
        String gysmc = Util.null2String(rs1.getString("tbr"));
        String gysmcname = getGysmc(gysmc);
        String gysrl = getGysrlId(gysmc);
        String gysrlname = resourceInfo.getLastname(gysrl);
        dataMap.put("gysmc",gysmc);
        dataMap.put("gysmcname",gysmcname);
        dataMap.put("gysrl",gysrl);
        dataMap.put("gysrlname",gysrlname);
        mapList.add(dataMap);
    }

    //明细表2
    rs1.executeQuery("select cjmc from formtable_main_683_dt4 where mainid='"+mainid+"' and sftt='0'");
    while (rs1.next()){
        Map<String, String> dataMap = new HashMap<>();
        String cjmc = Util.null2String(rs1.getString("cjmc"));
        String cjmcname = getGysmc(cjmc);
        String gysrl = getGysrlId(cjmc);
        String gysrlname = resourceInfo.getLastname(gysrl);
        dataMap.put("gysmc",cjmc);
        dataMap.put("gysmcname",cjmcname);
        dataMap.put("gysrl",gysrl);
        dataMap.put("gysrlname",gysrlname);
        mapList.add(dataMap);
    }
    if(mapList.size()>0){
        jsonData.put("flag",true);
        jsonData.put("dataList",mapList);
    }
    out.print( jsonData.toJSONString() );
    bb.writeLog( "getXylcspzDtl_Ajax=" + jsonData.toJSONString() );
%>
<%!
    public static String getGysmc(String id) {
        RecordSet rs = new RecordSet();
        String gysmc = "";
        rs.executeQuery( "select gysmc from uf_srm_gyskpx where id='" + id + "'" );
        rs.next();
        gysmc = Util.null2String( rs.getString( "gysmc" ) );
        return gysmc;
    }
    public static  String getGysrlId(String gysmc){
        RecordSet rs = new RecordSet();
        rs.executeQuery("select t2.id from uf_srm_gyskpx t1, hrmresource t2  " +
                "where t1.gysbm=t2.loginid and t1.id ='"+gysmc+"'");
        rs.next();
        String id = Util.null2String(rs.getString(1));
        return id;
    }
%>

